package game.utils;

import game.frame.MainFrame;
import game.roles.enemys.*;
import game.roles.visual.BackgroundMaps;

import java.util.Random;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.7
 * Time: 16:37
 * Description: 产生怪物的工具类
 */
public class EnemyFactory {
    /**
     * 产生怪物1的计算器
     */
    private int count1;

    /**
     * 产生怪物2的计算器
     */
    private int count2;

    /**
     * 产生怪物3的计时器
     */
    private int count3;

    /**
     * 产生怪物4的计数器
     */
    private int count4;


    private boolean creatBoss1 = true;

    private boolean creatBoss2 = true;

    public void creatSoldiers() {

//        玩家行走500米后产生第一种杂兵
        if (BackgroundMaps.mapX <= -500) {
            createSolider3();
        }

//        玩家行走100后产生第一种杂兵，并在3000处停止产生
        if (BackgroundMaps.mapX <= -100) {
            createSolider1();
        }

        //玩家行走500后产生新杂兵,
        if (BackgroundMaps.mapX <= -1000) {
            createSolider2();
        }

//        到地图1500处产生第一个boss
        if (BackgroundMaps.mapX <= -1500 && creatBoss2) {
            MainFrame.roleList.add(new Boss2());
            BackgroundMaps.mapMoveOrNot = false;
            creatBoss2 = false;
        }

        //逃兵将在400米后开始产生,在4100米后结束
        if (BackgroundMaps.mapX <= -400 && BackgroundMaps.mapX >= -4100) {
            creatSolider4();
        }

//        到地图底部产生最后一个boss
        if (BackgroundMaps.mapX <= -4200 && creatBoss1) {
            MainFrame.roleList.add(new Boss());
            BackgroundMaps.mapMoveOrNot = false;
            //避免重复产生boss
            creatBoss1 = false;
        }

    }

    private void creatSolider4() {
        this.count4++;
        if (this.count4 > 80) {
            this.count4 = 0;
            int num = 1 + new Random().nextInt(3);
            for (int i = 0; i < num; i++) {
                MainFrame.roleList.add(new Solider4());
            }
        }
    }

    /**
     * 产生怪物
     */
    public void createSolider1() {
        this.count1++;
        if (this.count1 > 100) {
            this.count1 = 0;
            int num = 1 + new Random().nextInt(3);
            for (int i = 0; i < num; i++) {
                MainFrame.roleList.add(new Soldier1());
            }
        }
    }

    public void createSolider2() {
        this.count2++;
        if (this.count2 > 100) {
            this.count2 = 0;
            int num = 1 + new Random().nextInt(5);
            for (int i = 0; i < num; i++) {
                MainFrame.roleList.add(new Solider2());
            }
        }
    }

    /**
     * 产生怪物
     */
    public void createSolider3() {
        this.count3++;
        if (this.count3 > 80) {
            this.count3 = 0;
            int num = 1 + new Random().nextInt(3);
            for (int i = 0; i < num; i++) {
                MainFrame.roleList.add(new Solider3());
            }
        }
    }
}
